var searchObj = {method:"search",params:1};
var checkboxName = 'check';

function delOne(id){
	layer.confirm(delObj.tip, {
	  	icon: 3, title:'提示'
	},function(){
		$.post(delObj.url, {"id":id},function(data) {
			if (data.msg) {
				layer.msg("删除成功");
				setTimeout(searchObj.method+"("+searchObj.params+")",0);
			}else{
				layer.msg("删除失败");
			}
		});
	});
}

function delMultil(){
	var checks = $("input[name='"+checkboxName+"']:checked");
	if(checks.length == 0){
		layer.msg("请选择要删除的数据");
		return;
	}
	var ids = [];
	for(var i=0;i < checks.length;i++){
		ids.push($(checks[i]).val());
	}
	delOne(ids.toString());
}

function stopOne(id,status){
	var tip = stopObj.stopTip;
	if(status == 1){
		tip = stopObj.startTip;
	}
	layer.confirm(tip, {
	  	icon: 3, title:'提示'
	},function(){
		$.post(stopObj.url, {"id":id,"status":status},function(data) {
			if (data.msg) {
				layer.msg("操作成功");
				setTimeout(searchObj.method+"("+searchObj.params+")",0);
			}else{
				layer.msg("操作失败");
			}
		});
	});
}

function stopMultil(status){
	var checks = $("input[name='"+checkboxName+"']:checked");
	if(checks.length == 0){
		if(status == -1){
			layer.msg("请选择要停用的数据");
		}else{
			layer.msg("请选择要启用的数据");
		}
		return;
	}
	var ids = [];
	for(var i=0;i < checks.length;i++){
		ids.push($(checks[i]).val());
	}
	stopOne(ids.toString(),status);
}

function reset(){
	$.each(resetObjs,function(k,v){
		$("#"+v.id).val(v.value);
	});
	setTimeout(searchObj.method+"("+searchObj.params+")",0);
}

function enterSearch(event){
	var e = event || window.event
	if(e.keyCode == 13){
		setTimeout(searchObj.method+"("+searchObj.params+")",0);
	}
}

function checkEmpty(){
	var value = arguments[0];
	if(!value || value == null || value == 'null' || $.trim(value).length == 0 | $.trim(value) == ''){
		if(arguments.length == 2){
			layer.msg(arguments[1]);
		}
		return true;
	}
	return false;
}

//是否正整数
var positiveNumRegex = /^[1-9]+[0-9]*$/;
function isPositiveNum(){
	var value = arguments[0];
	if(!positiveNumRegex.test(value)){
		layer.msg(arguments[1]);
		return false;
	}
	return true;
}

var numRegex = /^[0-9]+$/;
function isNum(){
	var value = arguments[0];
	if(!numRegex.test(value)){
		layer.msg(arguments[1]);
		return false;
	}
	return true;
}

var ipRegex = /([0-9]{1,3}\.{1}){3}[0-9]{1,3}/;
function isIp(){
	var value = arguments[0];
	if(!ipRegex.test(value)){
		layer.msg(arguments[1]);
		return false;
	}
	return true;
}

function listImgs(id){
	layer.open({
		title:"图片列表",
		type: 1,
		area : [ '850px', '600px' ],
		content: $('#imgs'), //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
		close: function(){
			
		},
		success:function(){
			$.ajax({
				type : "post",
				url : "listFiles",
				data : {
					"taskId":id,
					"flag":"img",
					"taskName":taskName
				},
				dataType : "json",
				success : function(data) {
					var html ='';
					$.each(data.datas,function(k,v){
						html += '<div class="col-md-3 mix photography">'
								+'<div class="hover-effect">'
								+'<div class="img">'
								+'<img width="150px" height="150px" src="http://localhost:800/'+v+'" alt="" />'
								+'</div>'
//								+'<div class="info">'
//                                +'<a href="http://localhost:800/'+v+'" data-lightbox="图片-'+k+'" data-title="图片 '+k+'" class="mix-zoom"><i class="glyphicon glyphicon-search"></i></a>'
//                                +'</div>'
                                +'</div>'
								+'</div>';
					});
					$(".mix-grid").html(html);
					$('.mix-grid').removeAttr("id");
					$('.mix-grid').mixItUp();
				}
			})
		}
	});
}
function listVideos(id){
	layer.open({
		title:"视频预览",
		type: 1,
		area : [ '850px', '600px' ],
		content: $('#videos'), //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
		close: function(){
			
		},
		success:function(){
			$.ajax({
				type : "post",
				url : "listFiles",
				data : {
					"taskId":id,
					"flag":"video",
					"taskName":taskName
				},
				dataType : "json",
				success : function(data) {
					$.each(data.datas,function(k,v){
						$("#src").attr("src","http://localhost:800/"+v);
						$("#videos").load();
					});
				}
			})
		}
	});
}

function listAudios(id){
	layer.open({
		title:false,
		type: 1,
//		area : [ '500px', '300px' ],
		content: $('#myAudio'), //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
		close: function(){
			
		},
		success:function(){
			$.ajax({
				type : "post",
				url : "listFiles",
				data : {
					"taskId":id,
					"flag":"audio",
					"taskName":taskName
				},
				dataType : "json",
				success : function(data) {
					$.each(data.datas,function(k,v){
						$("#audioSrc").attr("src","http://localhost:800/"+v);
						$("#audio").load();
					});
				}
			})
		}
	});
}